/**
 * Created by dale on 2017/10/9.
 */
$(document).ready(function () {


    var um = UM.getEditor('myEditor',{
        imageUrl:baseUrl+"frontend/article/uploadImgs", //处理图片上传的接口
        imageFieldName:"upfile", //上传图片的表单的name
        toolbar:['source | undo redo | bold italic underline strikethrough | superscript subscript | forecolor backcolor | removeformat |',
            'insertorderedlist insertunorderedlist | selectall cleardoc paragraph | fontfamily fontsize' ,
            '| justifyleft justifycenter justifyright justifyjustify |',
            'link unlink | image ',
            '| horizontal  formula'],
        imagePath : '',
    });
    var form = new xhForm($('#xh_form'));
    form.parse();
    $(".form-date").datetimepicker({format: 'yyyy-mm-dd', language: 'zh-CN', minView: "month", autoclose: true});
    var iArtType = addressUri.getParam('iArtType');
    if(iArtType==3){
        $('#tTime').remove();
    }
    $('[name=iArtType]').val(iArtType);
    if(artInfo!=1){
        form.fill(artInfo);
        um.ready(function() {//编辑器初始化完成再赋值
            if(artInfo['mText']!=null){
                um.setContent(artInfo['mText']);
            }
        });
    }


    form.bindRequired($('#bt_modal_confirm',parent.document));

    $('#submit').click(function () {
        $.ajax({
            url:baseUrl+'frontend/article/saveArticle',
            data:$('#xh_form').serialize(),
            type:'POST',
            success:function (data) {
                $('#bt_modal_confirm',parent.document).addClass('disabled');
                window.top.xhTop.closeModal();
                window.top.xhTop.closeActiveTab();
            },
            error:function (data) {
                window.top.swal(
                    data['responseText'],
                    '',
                    'error'
                );
            }
        });
    });

    $('#cancel').click(function () {
        window.top.xhTop.closeActiveTab();
    });


});